package com.vogue.meeting.fluent.dao.impl;

import cn.hutool.crypto.SecureUtil;
import com.vogue.meeting.common.web.domain.Result;
import com.vogue.meeting.common.web.domain.ResultCode;
import com.vogue.meeting.fluent.dao.base.UserBaseDao;
import com.vogue.meeting.fluent.dao.intf.UserDao;
import com.vogue.meeting.fluent.entity.UserEntity;
import com.vogue.meeting.fluent.wrapper.UserQuery;
import org.springframework.stereotype.Repository;

/**
 * UserDaoImpl: 数据操作接口实现
 *
 * 这只是一个减少手工创建的模板文件
 * 可以任意添加方法和实现, 更改作者和重定义类名
 * <p/>@author Powered By Fluent Mybatis
 */
@Repository
public class UserDaoImpl extends UserBaseDao implements UserDao {

    @Override
    public Result signUp(UserEntity user) {
        UserQuery query = new UserQuery();
        query.where.account().eq(user.getAccount());
        UserEntity userVo= mapper.findOne(query);
        if (userVo!=null){
           return Result.success(ResultCode.ACCOUNT_EXISTS);
        }
        user.setPassword(SecureUtil.md5(user.getPassword()));
        user.setEnable(true);
        user.setLocked(false);
        mapper.save(user);

        return Result.success(user);
    }
}
